package com.chengdu.chun.service.impl;

import com.chengdu.chun.mapper.UserMapper;
import com.chengdu.chun.po.User;
import com.chengdu.chun.service.UserService;
import com.chengdu.chun.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Spring的注解应该被添加到接口实现类当中，而不是在接口
 */
@Service
public class UserServiceImpl implements UserService {

    // 使用自动装配注解，自动匹配类型
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String name, String pass) {
        return userMapper.loginByNameAndPass(name, MD5Utils.reMD5(pass));
    }

    @Override
    public boolean insertUser(User user) {
        return userMapper.insertUser(user) > 0;
    }

    @Override
    public User userinfobyuid(Integer uid) {
        return userMapper.selectUserById(uid);
    }

    @Override
    public boolean updatePassword(Integer uid, String pass) {
        return userMapper.updatePassword(uid, MD5Utils.reMD5(pass)) > 0;
    }
}
